<?php session_start(); ?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
$db_server = "localhost";
$db_name = "chrishsu_membership";
$db_user = "chrishsu_member";
$db_passwd = "membership";
$rec = $_POST['rec'];
$comments = $_POST['comments'];

if(!@mysql_connect($db_server, $db_user, $db_passwd))
        die("無法對資料庫連線");

//資料庫連線採UTF8
mysql_query("SET NAMES utf8");

//選擇資料庫
if(!@mysql_select_db($db_name))
        die("無法使用資料庫");

if($_SESSION['username'] != null)
{
	$username = $_SESSION['username'];
	if($rec != null && $comments != null)
	{
        	$sql = "insert into recommendation (id, rec, comment) values ('$username', '$rec', '$comments')";
	}
        if(mysql_query($sql))
        {
                echo '謝謝您提供校友動向，我們於整理後將更新通訊錄';
        }
        else
        {
                echo '校友動向更新失敗';
        }
        echo '<meta http-equiv=REFRESH CONTENT=2;url=test_memberonly.php>';
}
else
{
        echo '請先登入';
        echo '<meta http-equiv=REFRESH CONTENT=2;url=test_login.html>';
}
?>
